<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <li
      :class="{ completed: item.isDone }"
      v-for="item in showList"
      :key="item.id"
    >
      <div class="view">
        <input
          :checked="item.isDone"
          @change="getValue($event,item.id)"
          class="toggle"
          type="checkbox"
        />
        <label>{{ item.name }}</label>
        <button @click="delTask(item.id)" class="destroy"></button>
      </div>
    </li>
  </ul>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex'

export default {
  computed: {
    ...mapState('todo', ['taskList']),
    ...mapGetters('todo', ['showList'])
  },
  methods: {
    ...mapMutations('todo', ['undateTaskIsDone', 'delTask']),
    getValue (e, id) {
      console.log(id)
      this.undateTaskIsDone({ value: e.target.checked, id: id })
    }
  }
}
</script>
